package com.xzy.urp.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    public static final String INCR_QUEUE = "incrQueue";
    public static final String DECR_QUEUE = "decrQueue";
    public static final String URP_EXCHANGE = "urpExchange";


    @Bean
    public Queue incrQueue(){
        return new Queue(INCR_QUEUE);
    }
    @Bean
    public Queue decrQueue(){
        return new Queue(DECR_QUEUE);
    }

    @Bean
    public TopicExchange urpExchange(){
        return new TopicExchange(URP_EXCHANGE);
    }

    @Bean
    public Binding stockQueueBind(){
        return BindingBuilder.bind(incrQueue()).to(urpExchange()).with("urp.stock.incr");
    }
    @Bean
    public Binding orderQueueBind(){
        return BindingBuilder.bind(decrQueue()).to(urpExchange()).with("urp.stock.decr");
    }
}
